#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>


int main(int argc, char const *argv[])
{
    struct sockaddr_in serveraddr,clientaddr;
    int sockfd=socket(AF_INET, SOCK_DGRAM,0);

    serveraddr.sin_family=AF_INET;
    serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
    serveraddr.sin_port=htons(atoi(argv[2]));

    socklen_t len=sizeof(serveraddr);
    bind(sockfd,(struct sockaddr *)&serveraddr,len);
    
    char recvbuf[128]={0};
    while(1)
    {
        if(recvfrom(sockfd,recvbuf,sizeof(recvbuf),0,(struct sockaddr *)&clientaddr,&len)>0)
        {
            printf("recv: %s\n",recvbuf);
            memset(recvbuf,0,128);
        }
    }
    return 0;
}

